package org.dhbw.oodb.dmlp;

import javax.persistence.EntityManager;
import javax.sql.DataSource;



import org.dhbw.oodb.dmlp.dao.CustomerDaoImpl;
import org.dhbw.oodb.dmlp.dao.CustomerJPADao;
import org.dhbw.oodb.dmlp.entity.Customer;
import org.dhbw.oodb.dmlp.jpql.EMFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;


public class Main {

	/**
	 * @param args
	 */
	/*public static void main(String[] args) {
		
		BeanFactory factory = new XmlBeanFactory(
		          new ClassPathResource("application-context.xml"));
		
		//TestClass ts = (TestClass)factory.getBean("tstcls");
		Benchmark bench = (Benchmark)factory.getBean("benchmark");
		
		CustomerDaoImpl impl = (CustomerDaoImpl) factory.getBean("customerDAO");
		
		EntityManager em = EMFactory.getEntityManager();
			bench.setEntityManager(em);
		
		//CustomerJPADao jpa = (CustomerJPADao) factory.getBean("customerJPA");
		
		DataSource source = (DataSource) factory.getBean("dataSource");
		if(bench.getCustomerDAO() == null){
			System.out.println("No CustomerDAO in Benchmark");
		}
		
		if(impl.dataSource == null){
			System.out.println("No Datasource in DAO");
		}
		
		if(source == null){
			System.out.println("No Datasource");
		}
		
		System.out.println("Starting overall benchmark. This may take some hours.");
		long sst = 0;
		long sct = 0;
		long sb = 0;
		long sbp = 0;
		long jst = 0;
		long jbt = 0;
		
		for(int i = 0; i<5; i++){
		System.out.println(i+") Starting benchmark using SimpleJdbcTemplate.update single Transaction");
		bench.BenchmarkSpringSingleTransaction(1000);
		System.out.println("done in "+bench.SNTJDBC/1000 + " seconds ("+bench.SNTJDBC+" milliseconds)");
		
		sst+=+bench.SNTJDBC/1000;
		
		System.out.println(i+") Starting benchmark using SimpleJdbcTemplate.update bulk Transaction");
		bench.BenchmarkSpringCustomTransaction(1000);
		System.out.println("done in "+bench.SNTJDBC/1000 + " seconds ("+bench.SNTJDBC+" milliseconds)");
		
		sct+=+bench.SNTJDBC/1000;
		
		System.out.println(i+") Starting benchmark using SimpleJdbcTemplate.batch");
		bench.BenchmarkSpringBatch(5000);
		System.out.println("done in "+bench.SNTJDBC/1000 + " seconds ("+bench.SNTJDBC+" milliseconds)");
		
		sb+=+bench.SNTJDBC/1000;
		
		System.out.println(i+") Starting benchmark using SimpleJdbcTemplate.batch with prepared statement");
		bench.BenchmarkSpringPreparedBatch(5000);
		System.out.println("done in "+bench.SNTJDBC/1000 + " seconds ("+bench.SNTJDBC+" milliseconds)");
		
		sbp+=+bench.SNTJDBC/1000;
		
		System.out.println(i+") Starting benchmark using JPA with single Transaction");
		bench.BenchmarkJPASingleTransaction(100);
		System.out.println("done in "+bench.SNTJDBC/1000 + " seconds ("+bench.SNTJDBC+" milliseconds)");
		
		jst+=+bench.SNTJDBC/1000;
		
		System.out.println(i+") Starting benchmark using JPA with bulk Transaction");
		bench.BenchmarkJPACustomTransaction(5000);
		System.out.println("done in "+bench.SNTJDBC/1000 + " seconds ("+bench.SNTJDBC+" milliseconds)");
		
		jbt+=+bench.SNTJDBC/1000;
		
		}
		
		System.out.println("Benchmarkresult: ");
		System.out.println("Spring JDBC Single Transaction AVG:" + sst/5);
		System.out.println("Spring JDBC Bulk Transaction AVG:" + sct/5);
		System.out.println("Spring JDBC Batch Execution AVG:" + sb/5);
		System.out.println("Spring JDBC Prepared Batch Execution AVG:" + sbp/5);
		System.out.println("JPA Single Transaction AVG:" + jst/5);
		System.out.println("JPA Batch Exection AVG:" + jbt/5);
	}*/

}
